<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<style>
    .docs-table {
        background: white;
        border-radius: 12px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
        overflow: hidden;
        border-collapse: separate;
        border-spacing: 0;
    }
    .docs-table thead {
        background: #f8f8f8;
    }
    .docs-table th {
        padding: 16px 12px;
        text-align: left;
        font-weight: 600;
        color: #1a1a1a;
        border-bottom: 2px solid #e5e5e5;
        font-size: 14px;
    }
    .docs-table td {
        padding: 16px 12px;
        border-bottom: 1px solid #f0f0f0;
        color: #1a1a1a;
        font-size: 14px;
    }
    .docs-table tbody tr {
        transition: all 0.3s ease;
    }
    .docs-table tbody tr:hover {
        background: #f8f8f8;
        transform: scale(1.01);
    }
    .action-links {
        display: flex;
        gap: 12px;
        align-items: center;
        justify-content: flex-start;
    }
    .action-btn {
        padding: 6px 16px;
        border-radius: 6px;
        font-size: 14px;
        font-weight: 500;
        border: none;
        cursor: pointer;
        transition: all 0.2s;
        margin: 0 2px;
        display: inline-flex;
        align-items: center;
        gap: 4px;
        background: #f5f5f5;
        color: #222;
        text-decoration: none;
        box-shadow: 0 1px 4px #0001;
    }
    .action-btn:hover {
        background: #e0e0e0;
        color: #111;
        box-shadow: 0 2px 8px #0002;
        transform: translateY(-1px);
    }
    .action-btn.primary {
        background: #1a1a1a;
        color: #fff;
    }
    .action-btn.primary:hover {
        background: #333;
    }
    .action-btn.danger {
        background: #d32f2f;
        color: #fff;
    }
    .action-btn.danger:hover {
        background: #b71c1c;
    }
</style>
<div style="margin-bottom: 30px;">
    <div style="font-size: 28px; font-weight: 600; color: #1a1a1a; margin-bottom: 8px;">文档管理</div>
    <div style="color: #666; font-size: 16px;">系统所有文档（可审核/设为私有）</div>
</div>
<h3>待审核文档</h3>
<table class="docs-table" style="width:100%;margin-bottom:32px;">
    <thead>
    <tr>
        <th>标题</th>
        <th>作者</th>
        <th>所属空间</th>
        <th>创建时间</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach var="doc" items="${pendingDocs}">
        <tr>
            <td>${doc.title}</td>
            <td>${doc.authorName}</td>
            <td>${doc.spaceName}</td>
            <td>${fn:substring(doc.createdAt, 0, 19)}</td>
            <td style="text-align:center;">
                <div class="action-links">
                    <a href="/document/detail/${doc.id}" class="action-btn primary">查看</a>
                    <form action="/user/admin/docs/approve/${doc.id}" method="post" style="display:inline; margin:0;">
                        <button type="submit" class="action-btn" onclick="return confirm('确定通过该文档审核并公开？')">通过</button>
                    </form>
                    <form action="/user/admin/docs/reject/${doc.id}" method="post" style="display:inline; margin:0;">
                        <button type="submit" class="action-btn danger" onclick="return confirm('确定驳回并设为私有？')">驳回</button>
                    </form>
                </div>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<c:if test="${empty pendingDocs}">
    <p style="margin-top:16px;color:#888;">暂无待审核文档。</p>
</c:if>
<h3>已公开文档</h3>
<table class="docs-table" style="width:100%;">
    <thead>
    <tr>
        <th>标题</th>
        <th>作者</th>
        <th>所属空间</th>
        <th>创建时间</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach var="doc" items="${publicDocs}">
        <tr>
            <td>${doc.title}</td>
            <td>${doc.authorName}</td>
            <td>${doc.spaceName}</td>
            <td>${fn:substring(doc.createdAt, 0, 19)}</td>
            <td style="text-align:center;">
                <div class="action-links">
                    <a href="/document/detail/${doc.id}" class="action-btn primary">查看</a>
                    <form action="/user/admin/docs/reject/${doc.id}" method="post" style="display:inline; margin:0;">
                        <button type="submit" class="action-btn danger" onclick="return confirm('确定设为私有？')">设为私有</button>
                    </form>
                </div>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<c:if test="${empty publicDocs}">
    <p style="margin-top:16px;color:#888;">暂无已公开文档。</p>
</c:if> 